package com.back_end.Array.find;

import java.util.Scanner;

public class FindArray {
    public  static int [] arr = new int[]{1,2,3,4,5,6,7,8,9};
    public static void main(String[] args) {
        System.out.println("请输入一个数，将在数组中查找：");
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        find(n);
    }

    public static void find(int f){
        for(int i=0;i<arr.length;i++){
            if(i==arr.length-1){ //先判断结束标志
                if (arr[i] == f) {
                    System.out.println("找到了，索引为：" + i);
                    break;
                }else{
                    System.out.println("没找到");
                    break;
                }
            }else{
                if(arr[i] == f){  //末尾之前的查找
                    System.out.println("找到了，索引为：" + i);
                    break;
                }
            }
        }
    }
}
